package com.imooc.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * <h1>有效期类型枚举</h1>
 * @Author: crowsjian
 * @Date: 2020/6/1 22:44
 */
@Getter
@AllArgsConstructor
public enum PeriodType {
    REGULAR("固定的（固定的日期）",1),
    SHIFT("变动的（以领取之日开始计算）",2),
    ;
    private String description;//有效期描述
    private Integer code;//有效期编码

    public static PeriodType of(Integer code){
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean->bean.code.equals(code))
                .findAny()
                .orElseThrow(()->new IllegalArgumentException(code + "not exists!"));
    }
}
